<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.prime.com.tr/ui">
    <h:head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <title>Add Sales Inquiry</title>
    </h:head>
    <f:view beforePhase="#{UserDisplayManagedBean.doDisplay}">
        <f:view beforePhase="#{SalesInquiryManagedBean.initView}">
            <h:body>
                <div id="top">
                    <h:graphicImage value="/image/newHeader.jpg"/>
                </div>

                <h:form id="form">
                    <!-- IDLE DIALOG for -->
                    <p:confirmDialog message="You have been idle for 5 minutes. Do you want to continue?"  
                                     showEffect="bounce" hideEffect="explode"  
                                     header="Warning message" severity="alert" widgetVar="confirmation">  
                        <p:commandButton value="Yes" onclick="confirmation.hide()" type="button" /> 
                        <p:commandButton value="No" update="panel" oncomplete="confirmation.hide()"  
                                         actionListener="#{UserManagedBean.doLogout}" /> 
                    </p:confirmDialog>

                    <p:idleMonitor timeout="300000" onidle="confirmation.show()" />  
                    <!--END OF IDLE DIALOG-->

                    <p:growl id="msgs" showDetail="true" />

                    <div id="content">

                        <table>
                            <tr>
                                <td>
                                    <p:toolbar style="font-size:12px;margin-top:0%;height:30px;width:200px"> 
                                        <p:toolbarGroup align="right">
                                            <p:button title="Home" image="ui-icon-home" outcome="SalesDeptWorkspace"/>                                   
                                            <p:button title="Notes" image="ui-icon-note" outcome="tasks"/>                                   
                                            <p:button title="Mail" outcome="messages" image="ui-icon-mail-closed"/>                                   
                                            <p:button title="Edit Preferences" image="ui-icon-gear"/>                                    
                                            <p:button title="Help" image="ui-icon-help"/>
                                            <p:commandButton title="Log Out" immediate="true" type="submit" image="ui-icon-close" actionListener="#{UserManagedBean.doLogout}"/> 
                                        </p:toolbarGroup>
                                    </p:toolbar></td>
                                <td>
                                    <h:graphicImage value="newdoc.png" style="width:45px;height:45px"/>
                                    <h:outputText value="New Sales Inquiry" style="font-family:Tahoma;font-size:20px;font-weight:bolder"/>
                                    <p:separator style="width:1070px"/>
                                </td>

                            </tr>
                            <tr>
                                <td style="vertical-align:top">
                                    <p:menu style="width:200px;font-size: 12px;font-family: Tahoma;border-style: ridge">  
                                        <p:submenu label="Sales Force Automation" >  
                                            <p:menuitem value="Customers" url="http://localhost:8080/MerlionERP-war/CRM/customers.xhtml" ajax="false" icon="ui-icon ui-icon-person"/>  
                                            <p:menuitem value="Contacts" url="http://localhost:8080/MerlionERP-war/CRM/contacts.xhtml" ajax="false" icon="ui-icon ui-icon-person" />
                                            <p:menuitem value="Leads" url="http://localhost:8080/MerlionERP-war/CRM/salesLeads.xhtml" ajax="false" icon="ui-icon ui-icon-person" />
                                        </p:submenu>
                                        <p:submenu label="Sales Order Processing">
                                            <p:menuitem value="Pricebooks" url="http://localhost:8080/MerlionERP-war/CRM/pricebooks.xhtml" ajax="false" icon="ui-icon ui-icon-document"/>
                                            <p:menuitem value="Inquiries" url="http://localhost:8080/MerlionERP-war/CRM/salesInquiries.xhtml" ajax="false" icon="ui-icon ui-icon-document"/>
                                            <p:menuitem value="Quotations" url="http://localhost:8080/MerlionERP-war/CRM/quotations.xhtml" ajax="false" icon="ui-icon ui-icon-document"/>
                                            <p:menuitem value="Purchase Orders" url="http://localhost:8080/MerlionERP-war/CRM/purchaseOrders.xhtml" ajax="false" icon="ui-icon ui-icon-document"/>
                                            <p:menuitem value="Sales Orders" url="http://localhost:8080/MerlionERP-war/CRM/salesOrders.xhtml" ajax="false" icon="ui-icon ui-icon-document"/>
                                            <p:menuitem value="Delivery Orders" url="http://localhost:8080/MerlionERP-war/CRM/deliveryOrdersCRM.xhtml" ajax="false" icon="ui-icon ui-icon-document"/>
                                        </p:submenu>  
                                    </p:menu>
                                    <p:menu type="tiered" style="width:200px;font-family:Tahoma;font-size:12px">
                                        <p:submenu label="Create New" icon="ui-icon ui-icon-extlink">  
                                            <p:menuitem value="Customer" url="http://localhost:8080/MerlionERP-war/CRM/createNewCustomer.xhtml" />
                                            <p:menuitem value="Sales Lead" url="http://localhost:8080/MerlionERP-war/CRM/createNewSalesLead.xhtml" /> 
                                            <p:menuitem value="Contact" url="http://localhost:8080/MerlionERP-war/CRM/createNewContact.xhtml" />
                                            <p:menuitem value="Inquiry" url="http://localhost:8080/MerlionERP-war/CRM/addSalesInquiry.xhtml"/>
                                            <p:menuitem value="Quotation" url="http://localhost:8080/MerlionERP-war/CRM/addQuotation.xhtml"/>
                                            <p:menuitem value="Purchase Order" url="http://localhost:8080/MerlionERP-war/CRM/addPurchaseOrder.xhtml"/>
                                            <p:menuitem value="Sales Order" url="http://localhost:8080/MerlionERP-war/CRM/addSalesOrder.xhtml"/>
                                            <p:menuitem value="Delivery Order" url="http://localhost:8080/MerlionERP-war/CRM/addDeliveryOrder.xhtml"/>      
                                        </p:submenu>
                                    </p:menu>
                                    <p:calendar mode="inline" style="font-size:11px;font-family:Tahoma"/>
                                </td>
                                <td style="vertical-align:top">


                                    <p:panel id="paneldisplay" style="border-style:hidden;width:1080px;font-family:Tahoma;font-size:12px">

                                        <h:panelGrid columns="10" style="width:1080px" cellpadding="4">

                                            <h:outputLabel value="Inquiry Name"/>
                                            <h:outputText value=":"/>
                                            <p:inputText value="#{SalesInquiryManagedBean.newInquiry.documentName}"/>

                                            <h:outputText value=""/>
                                            <h:outputText value=""/>
                                            <h:outputText value=""/>
                                            <h:outputText value=""/> 
                                            <h:outputText value=""/>
                                            <h:outputText value=""/> 
                                            <h:outputText value=""/>


                                            <h:outputLabel for="DateIssued" value="Date Issued"/>
                                            <h:outputText value=":"/>
                                            <p:calendar id="DateIssued" value="#{SalesInquiryManagedBean.newInquiry.dateIssued}" pattern="dd/MM/yyyy" required="true" /> 
                                            <p:message for="DateIssued"/>
                                            <h:outputText value=""/>

                                            <h:outputText value=""/>
                                            <h:outputText value=""/> 
                                            <h:outputText value=""/>
                                            <h:outputText value=""/> 
                                            <h:outputText value=""/>

                                            <h:outputLabel for="ClientName" value="Client Name" />
                                            <h:outputText value=":"/>
                                            <h:selectOneMenu id="ClientName" required="true" value="#{SalesInquiryManagedBean.newInquiry.clientId}">
                                                <f:selectItem itemLabel="Select Client [Type - ID - Name]" itemValue=""/>
                                                <f:selectItems value="#{SalesInquiryManagedBean.clientList}" var="clients"
                                                               itemLabel ="#{clients.clientType}    -   #{clients.id}    -   #{clients.name}" itemValue="#{clients.id}"/>


                                                <p:ajax update="ContactName" listener="#{SalesInquiryManagedBean.handleClientChange}"/>
                                            </h:selectOneMenu>
                                            <p:commandLink update="display1" oncomplete="customerDialog.show()" title="Client List">
                                                <p:graphicImage value="book.png" style="width:20px;height:20px;text-align: left;margin-left:-145px"/>                 
                                            </p:commandLink>
                                            <p:message for="ClientName"/>

                                            <h:outputLabel for="ContactName" value="Contact Name" />
                                            <h:outputText value=":"/>

                                            <h:selectOneMenu id="ContactName" value="#{SalesInquiryManagedBean.newInquiry.contactId}">

                                                <f:selectItem itemLabel="Select Contact [ID - Name]" itemValue=""/>
                                                <f:selectItems value="#{SalesInquiryManagedBean.contactList}" var="contacts"
                                                               itemLabel ="#{contacts.id} - #{contacts.firstName} #{contacts.lastName}" itemValue="#{contacts.id}"/>    
                                            </h:selectOneMenu>
                                            <h:outputText value=""/>
                                            <h:outputText value=""/>


                                            <h:outputText value =" Pricing Type"/>
                                            <h:outputText value=":"/>
                                            <h:selectOneMenu value ="#{SalesInquiryManagedBean.pricingType}" >
                                                <f:selectItem itemLabel="-None-" itemValue=""/>
                                                <f:selectItem itemLabel="Flat" itemValue="F"/>
                                                <!-- <f:selectItem itemLabel="Differential" itemValue="D"/>-->
                                                <p:ajax update="panel"/>
                                            </h:selectOneMenu>
                                            <h:outputText value=""/> 
                                            <h:outputText value=""/>

                                        </h:panelGrid>

                                        <h:panelGrid columns="1" style="width:1080px" cellpadding="4">
                                            <h:outputText value="Description" style="font-weight:bolder"/>

                                            <p:inputTextarea value="#{SalesInquiryManagedBean.newInquiry.description}" style="height:100px; width:1060px"/>

                                        </h:panelGrid>

                                        <p:dialog header="Client Detail" widgetVar="customerDialog" resizable="false"  
                                                  width="700" showEffect="drop" hideEffect="drop">  
                                            <center>
                                                <h:panelGrid id="display1" columns="1" cellpadding="4" style="font-family:Tahoma;font-size:12px" >  

                                                    <p:dataTable id="childPanel1" value="#{SalesInquiryManagedBean.clientList}"
                                                                 var="clients" paginator="true" rows="5">                          

                                                        <p:column headerText="Client ID">
                                                            <h:outputText value ="#{clients.id}"/>
                                                        </p:column>

                                                        <p:column headerText="Client Name">
                                                            <h:outputText value="#{clients.name}"/>
                                                        </p:column>

                                                        <p:column headerText="Client Type">
                                                            <h:outputText value="#{clients.clientType}"/>
                                                        </p:column>

                                                        <p:column headerText="Contact Number">
                                                            <h:outputText value="#{clients.contactNum}"/>
                                                        </p:column>

                                                        <p:column headerText="Business Type">
                                                            <h:outputText value="#{clients.businessType}"/>
                                                        </p:column>

                                                    </p:dataTable>
                                                    <p:ajaxStatus style="width:16px;height:16px;">  
                                                        <f:facet name="start">  
                                                            <h:graphicImage value="25(2).gif" />  
                                                        </f:facet>  

                                                        <f:facet name="complete">  
                                                            <h:outputText value="" />  
                                                        </f:facet>  
                                                    </p:ajaxStatus> 

                                                </h:panelGrid></center>
                                        </p:dialog>
                                    </p:panel>

                                    <div id="productContent">
                                        <p:panel id="panel" style="border-style:hidden;font-family:Tahoma;font-size:12px">  
                                            <h:graphicImage value="box.png" style="width:35px;height:35px"/>
                                            <h:outputText value="Product Details" style="font-family:Tahoma;font-size:20px;font-weight:bolder"/>
                                            <p:separator style="width:1070px"/>
                                            <h:panelGrid columns="3" id="grid" style="width:540px" cellpadding="4">  

                                                <h:outputLabel value="Product Name" for="productId"/>
                                                <h:outputLabel value=":" style="margin-left:30px"/>
                                                <h:selectOneMenu id="productId" value="#{SalesInquiryManagedBean.lineEntry.itemId}" >
                                                    <f:selectItem itemLabel="Select Product [Product Name - Base Price]" itemValue=""/>
                                                    <f:selectItems value="#{SalesInquiryManagedBean.productList}" var="products"
                                                                   itemLabel ="#{products.itemName}    -    #{products.price}" itemValue="#{products.id}"/>
                                                    <p:ajax update="pricebook"  listener="#{SalesInquiryManagedBean.handleProductChange}" /> 
                                                    <p:commandLink update="display2" oncomplete="productDialog.show()" title="Product List">
                                                        <p:graphicImage value="tag.png" style="width:20px;height:20px;text-align: left"/>                 
                                                    </p:commandLink>

                                                </h:selectOneMenu> 

                                                <h:outputLabel value="Pricebook" for="pricebook"/>
                                                <h:outputLabel value=":" style="margin-left:30px"/>
                                                <h:selectOneMenu id="pricebook"  value="#{SalesInquiryManagedBean.lineEntry.pricebookId}" >
                                                    <f:selectItem itemLabel="Select Pricebook" itemValue=""/>
                                                    <f:selectItems value="#{SalesInquiryManagedBean.pricebookList}" var="price"
                                                                   itemLabel ="#{price.id}" itemValue="#{price.id}"/>
                                                    <p:ajax update="price"   
                                                            listener="#{SalesInquiryManagedBean.handlePricebookChange}" /> 
                                                </h:selectOneMenu> 

                                                <h:outputLabel value="Quantity" for="quantity"/>
                                                <h:outputLabel value=":" style="margin-left:30px"/>
                                                <p:inputText id="quantity" required="true"   
                                                             value="#{SalesInquiryManagedBean.lineEntry.quantity}" >
                                                    <p:ajax update="pricebook price" event="keyup"
                                                            listener="#{SalesInquiryManagedBean.handlePricebookChange}" /> 
                                                </p:inputText>



                                                <h:outputLabel value="List Price"/>
                                                <h:outputLabel value=":" style="margin-left:30px" />
                                                <p:inputText id="price" value="#{SalesInquiryManagedBean.lineEntry.price}">
                                                    <p:ajax listener="#{SalesInquiryManagedBean.handlePriceChange}"/>
                                                </p:inputText>


                                            </h:panelGrid>  


                                            <p:commandButton value="Add" update="lineEntryList msgs @parent"  
                                                             action="#{SalesInquiryManagedBean.reinit}" style="margin-left:187px" image="ui-icon ui-icon-plus" >  
                                                <p:collector value="#{SalesInquiryManagedBean.lineEntry}"   
                                                             addTo="#{SalesInquiryManagedBean.lineEntryList}" />  
                                            </p:commandButton>  
                                            <p:commandButton value="Reset" type="reset" image="ui-icon ui-icon-arrowrefresh-1-s"/>  


                                            <p:dialog header="Product Detail" widgetVar="productDialog" resizable="false"  
                                                      width="700" showEffect="drop" hideEffect="drop">  
                                                <center>
                                                    <h:panelGrid id="display2" columns="1" cellpadding="4" style="font-family:Tahoma;font-size:12px" >  

                                                        <p:dataTable id="childPanel2" value="#{SalesInquiryManagedBean.productList}"
                                                                     var="products" paginator="true" rows="5">                          

                                                            <p:column headerText="ID">
                                                                <h:outputText value ="#{products.id}"/>
                                                            </p:column>

                                                            <p:column headerText="Name">
                                                                <h:outputText value="#{products.itemName}"/>
                                                            </p:column>

                                                            <p:column headerText="Base Price">
                                                                <h:outputText value="#{products.price}"/>
                                                            </p:column>

                                                            <p:column headerText="List Price(before Volume Discount)">
                                                                <h:outputText value="#{products.listPrice}"/>
                                                            </p:column>

                                                            <p:column headerText="Description">
                                                                <h:outputText value="#{products.description}"/>
                                                            </p:column>


                                                        </p:dataTable>

                                                    </h:panelGrid></center>
                                            </p:dialog>

                                            <p:ajaxStatus style="width:16px;height:16px;">  
                                                <f:facet name="start">  
                                                    <h:graphicImage value="25(2).gif" />  
                                                </f:facet>  

                                                <f:facet name="complete">  
                                                    <h:outputText value="" />  
                                                </f:facet>  
                                            </p:ajaxStatus> 

                                            <p:outputPanel id="lineEntryList">  

                                                <p:dataTable value="#{SalesInquiryManagedBean.lineEntryList}" var="lineEntry" 
                                                             rowEditListener ="#{SalesInquiryManagedBean.onRowEdit}" 
                                                             style="font-family:Tahoma;font-size:12px"  >  

                                                    <p:column>  
                                                        <f:facet name="header">  
                                                            <h:outputText value="Product ID" />  
                                                        </f:facet>  
                                                        <h:outputText value="#{lineEntry.itemId}" />  
                                                    </p:column>  

                                                    <p:column>  
                                                        <f:facet name="header">  
                                                            <h:outputText value="Product Name" />  
                                                        </f:facet>  
                                                        <h:outputText value="#{lineEntry.itemName}" />  
                                                    </p:column>  

                                                    <p:column headerText="Quantity" >  
                                                        <p:cellEditor>
                                                            <f:facet name="output">  
                                                                <h:outputText value="#{lineEntry.quantity}" />  
                                                            </f:facet>
                                                            <f:facet name="input">
                                                                <p:inputText value="#{lineEntry.quantity}" />
                                                            </f:facet>
                                                        </p:cellEditor>
                                                    </p:column>  

                                                    <p:column>
                                                        <f:facet name="header">
                                                            <h:outputText value="Base Price"/>

                                                        </f:facet>
                                                        <h:outputText value="#{lineEntry.basePrice}"/>
                                                    </p:column>

                                                    <p:column headerText="Price" style="width:100px;border-right-color:transparent">  
                                                        <p:cellEditor  >
                                                            <f:facet name="output">  
                                                                <h:outputText value="#{lineEntry.price}" />  
                                                            </f:facet>  
                                                            <f:facet name="input">
                                                                <h:inputText value="#{lineEntry.price}" >
                                                                    <p:ajax update="totalPrice"/></h:inputText>
                                                            </f:facet>
                                                        </p:cellEditor>
                                                    </p:column>

                                                    <p:column style="width:30px;border-left-color:transparent">    
                                                        <p:rowEditor/>
                                                    </p:column>


                                                    <p:column>
                                                        <f:facet name="header">
                                                            <h:outputText value="Total"/>
                                                        </f:facet>
                                                        <h:outputText id="totalPrice" value="#{lineEntry.totalPrice}"/>
                                                    </p:column>

                                                    <p:column>  
                                                        <f:facet name="header">  
                                                            <h:outputText value="Operation" />  
                                                        </f:facet>  
                                                        <p:commandLink value="Remove" update="form:lineEntryList" process="@this">  
                                                            <p:collector value="#{lineEntry}"  
                                                                         removeFrom="#{SalesInquiryManagedBean.lineEntryList}" />  
                                                        </p:commandLink>  
                                                    </p:column>  

                                                </p:dataTable>  
                                            </p:outputPanel>

                                        </p:panel>

                                    </div>

                                    <p:panel style ="text-align:right;font-family:Tahoma;border-style:hidden; font-size:12px">

                                        <p:commandButton style="text-align:right" value="Submit" update="paneldisplay" ajax="true" immediate="true" actionListener="#{SalesInquiryManagedBean.addSalesInquiry}"/>

                                    </p:panel>


                                    <p:confirmDialog message="Have you finished filling the form?"  
                                                     showEffect="blind" hideEffect="blind"  
                                                     header="Confirmation" severity="alert" widgetVar="confirmation">  

                                        <p:commandButton value="Yes" update="paneldisplay" oncomplete="confirmation.hide()"  
                                                         actionListener="#{SalesInquiryManagedBean.addSalesInquiry}" />  
                                        <p:commandButton value="No" onclick="confirmation.hide()" type="button" />   

                                    </p:confirmDialog>  



                                </td>
                            </tr>
                        </table>
                    </div>

                    <div id="bottom" class="bottom">
                        <h:graphicImage value="/image/merlionfooter.jpg"/>
                    </div>

                </h:form>

            </h:body>
        </f:view>
    </f:view>
</html>